<template>
	<view class="order-wrapper" :style="{paddingTop: paddingTop + 'px'}">
		
		<navBar title="我的评价" />
		
		<view class="order-tab" :style="{top: paddingTop + 'px'}">
			<u-tabs
				:list="list"
				:scrollable="false"
				:current="current"
				lineColor="#CF1A1B"
				lineWidth="70"
				lineHeight="4"
				:activeStyle="{
	  			color: '#CF1A1B',
				'font-size':'14px'
	  		}"
				:inactiveStyle="{
	  			color: 'rgba(0,0,0,0.65)',
				'font-size':'14px'
	  		}"
				itemStyle="height: 44px;"
				@change="handleTab"
			>
			</u-tabs>
		</view>
		<view v-if="orderList.length == 0" class="empty">
			<image src="@/static/empty.png"></image>
			<text>无数据</text>
		</view>
		<!-- 待评价列表 -->
		<view class="list-wrapper" v-if="current === 0">
			<view class="order-list" v-for="item in orderList" :key="item.id">
				<view class="order-item">
					<view class="order-item-h">
						<view class="store-name">
							<image src="@/static/store_bg.png" mode=""></image>
							<text class="name">{{ item.terminalName }}</text>
						</view>
						<view class="order-status">
							<text >待评价</text>
						</view>
					</view>
					<view class="order-item-c">
						<view class="goods-list">
							<view class="goods-item-box">
								<view class="goods-item" v-for="(goods,index) in item.orderItems" :key="goods.goodsId">
									<view class="goods-img">
										<image class="img"
											:src="goods.image ? goods.image : 'https://coach-vehicle-uat-1313990257.cos.ap-beijing.myqcloud.com/miniapp/order/goods_default_square.png'">
										</image>
									</view>
									<view v-if="item.orderItems.length === 1" class="goods-info">
										<view class="info">
											<view class="goods-name">{{	goods.goodsName }}</view>
										</view>
									</view>
								</view>								
							</view>
							<view class="goods-sum">
								共{{ item.totalQuality }}件
							</view>
						</view>
						
						<view class="goods-state">
							<view class="gs-item">
								<view class="gsi-label">
									<view class="gsil-tag"></view>
									<view class="gsil-state">
										{{ item.payTime	}} 下单
									</view>
								</view>
							</view>
						</view>
					</view>
					
					<view class="order-item-b">
						<button type="warn" size="mini" @click.stop="actionEvaluate(item)">去评价</button>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 已评价列表 -->
		<view class="list-wrapper" v-if="current === 1">
			<view class="tc-c-list" v-for="item in orderList" :key="item.id" @click.stop="gotoCommentDetail(item.id)">
				<!-- 头部基本信息 -->
				<view class="tc-cl-header">
					<view class="tc-clh-left">
						<view class="tc-clhl-img">
							<image :src="item.headImgUrl || currentImg" mode="scaleToFill"></image>
						</view>
						<view class="tc-clhl-baseInfo">
							<view class="tc-clhlb-number">
								<view class="tc-clhlbn-phone">
									{{ item.driverMobile && item.driverMobile.replace(item.driverMobile.substring(3, 7), '****') }}
								</view>
								<view class="tc-clhlbn-car" v-if="item.plateNum">
									{{ item.plateNum && item.plateNum.replace(item.plateNum.substring(2), '******')}}
								</view>
							</view>
							<view class="tc-clhlb-score">
								<uni-rate readonly :max="5" :size="16" :value="item.score" allow-half activeColor="#CF1A1B"/>
								<text :class="['siml-text', item.score && 'text-color']">
									{{ item.score ? parseInt(item.score) === parseFloat(item.score) ? `${item.score}.0` : item.score : '暂无评分' }}
								</text>
							</view>
						</view>
					</view>
					<view class="tc-clh-right">
						{{ item.createdTime }}
					</view>
				</view>
				<!-- 评价内容 -->
				<view class="tc-cl-main">
					<view class="tc-clm-content ellipsis-2">{{ item.content }}</view>
					<view class="tc-clm-store" @click.stop="gotoStoreDetail(item)">
						<view class="tc-clms-left">
							<image :src="item.photo1 || currentImg" mode=""></image>
							<view class="tc-clmsl-name">{{ item.terminalName || ''}}</view>
						</view>
						<view class="tc-clms-right">
							<uni-icons type="right" size="15" color="rgba(0, 0, 0, 0.90)"></uni-icons>
						</view>
					</view>
				</view>
				<!-- 回复 -->
				<view class="tc-cl-reply" v-if="item.replyState === 'Y'">
					<view class="tc-clr-icon">
						<image src="https://coach-vehicle-uat-1313990257.cos.ap-beijing.myqcloud.com/miniapp/store/ic_huifu.png" mode=""></image>
					</view>
					<view class="tc-clr-des ellipsis-2">
						<text class="tc-clrd-label">门店回复：</text>
						<text class="tc-clrd-value">
							{{ item.replyContent }}
							</text>
					</view>
				</view>
			</view>
		</view>
		
		
		
		<uni-load-more :status="status" v-if="loadVisible" :contentText="contentText" />
	</view>
</template>

<script>
	import currentImg from '@/static/currentImg.png'
	import navBar from '@/components/navBar.vue'
	import {
		mapGetters
	} from 'vuex'
	export default {
		components: {
			navBar
		},
		data() {
			return {
				currentImg,
				paddingTop: '',
				current: 0,
				list: [{
						name: '待评价',
						status: 6
					}, {
						name: '已评价',
						status: 1,
					}
				],
				pageNum: 1,
				pageSize: 10,
				orderList: [],
				total: 0,
				emptyVisible: false,
				status: 'more',
				loadVisible: false,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了",
				},
			}
		},
		computed: {
			...mapGetters('user', ['getUserInfo']),
			...mapGetters('global', ['getNowLocation'])
		},
		methods: {
			// 去评价
			actionEvaluate(item){
				uni.navigateTo({
					url: `/orderPack/evaluate/actionEvaluate?id=${item.id}&storeName=${item.terminalInfo.name}&storeImage=${item.terminalInfo.photo1}`,
				})
			},
			// 门店详情
			gotoStoreDetail(item){
				const {  longitude, latitude } = this.getNowLocation
				uni.navigateTo({
				  url: `/storePack/detail/detail?terminalId=${item.terminalId}&longitude=${longitude}&latitude=${latitude}`
				})
			},
			// 评价详情
			gotoCommentDetail(id){
				uni.navigateTo({
					url: `/storePack/detail/commentDetail?id=${id}`
				})
			},
			handleTab(e) {
				uni.showLoading({
					title: '加载中...'
				})
				this.pageNum = 1
				this.orderList = []
				this.current = e.index
				this.initData()
			},
			//获取数据
			async initData() {
				uni.showLoading({
					title: '加载中...'
				})
				try {
					const data = {
						pageNum: this.pageNum,
						pageSize: this.pageSize,
					}
					
					const res = await this.$request({
						method: 'POST',
						url: this.current === 0 ? '/order-center/car-owner-order/getTodoEvaluate' : '/user-center/terminalEvaluation/getDoneEvaluate',
						data
					})
					this.orderList = this.orderList.concat(res.datas.data)
					this.total = res.datas.count
					
					this.loadVisible = this.total > this.pageSize
					this.emptyVisible = this.total === 0
					uni.hideLoading()
				} catch (res) {
					uni.hideLoading()
					uni.showToast({
						title: '请求失败',
						icon: 'error'
					})
				}

				uni.stopPullDownRefresh();
			},
		},

		onReachBottom() {
			if (this.orderList.length >= this.total) {
				this.status = 'noMore'
				return
			}
			this.loadVisible = true
			this.status = 'loading'
			this.pageNum++
			this.initData()
		},
		onPullDownRefresh() {
			this.loadVisible = false
			this.pageNum = 1
			this.total = 0
			this.orderList = []
			this.initData()
		},
		onLoad() {
			this.initData()
			this.paddingTop = this.$store.getters['global/getSystemInfo'].navBarHeight
		}

	}
</script>

<style lang="scss" scoped>
	.order-wrapper {
		width: 100%;
		height: 100%;
		font-size: 14px;
		box-sizing: border-box;
		padding-bottom: env(safe-area-inset-bottom);

		/deep/ .u-tabs__wrapper__nav__line {
			margin-left: 16px;
		}

		/deep/ .u-tabs__wrapper__nav__item {
			padding: 0;
		}

		.empty {
			width: 100%;
			height: 80%;
			position: absolute;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			image {
				width: 220px;
				height: 180px;
			}

			text {
				font-size: 30rpx;
				color: rgba(0, 0, 0, 0.45);
				line-height: 30rpx;
			}
		}

		.order-tab {
			z-index: 99;
			position: fixed;
			width: 100%;
			background-color: #FFFFFF;
		}

		.list-wrapper {
			padding-top: 108rpx;
		}

		.order-list {
			.order-item {
				background: #fff;
				margin-bottom: 20rpx;
				box-sizing: border-box;
				padding: 22rpx 32rpx;
				

				.order-item-h {
					display: flex;
					justify-content: space-between;
					align-items: center;
					align-content: center;
					border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);
					padding: 10rpx 0 30rpx;			
					font-size: 14px;

					.store-name {
						display: flex;
						align-items: center;
						flex: 1;
						color: rgba(0, 0, 0, 0.85);
						width: calc(100% - 200rpx);
						image {
							width: 36rpx;
							height: 36rpx;
						}

						.name {
							flex: 1;
							max-width: calc(100% - 46rpx);
							word-wrap: break-all;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 1;
							text-shadow: 0 0 0.1px currentcolor;
							line-clamp: 1;
							-webkit-box-orient: vertical;
							margin-left: 12rpx;
						}
					}

					.order-status {
						width: 200rpx;
						text-align: right;
						color: rgba(246, 139, 83, 1);
					}
				}

				.order-item-c {
					overflow-x: scroll;

					.goods-list {
						display: flex;
						justify-content: space-between;
						align-items: center;
						border-bottom: 2rpx solid rgba(0, 0, 0, 0.1);
					}
					.goods-item-box {
						flex: 1;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						overflow-x: scroll;
					}

					.goods-item {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding: 28rpx 0;
						margin-right: 20rpx;
						
						.goods-img {
							.img {
								height: 124rpx;
								width: 124rpx;
							}
						}
						
						.goods-info {
							flex: 1;
							display: flex;
							height: 180rpx;
							justify-content: flex-start;
							align-items: center;
							width: calc(100% - 200rpx);
						
							.info {
								width: 100%;
								margin-left: 26rpx;
							}
						
							.goods-name {
								font-size: 15px;
								font-weight: 500;
								color: rgba(0, 0, 0, 0.85);
								margin-bottom: 14rpx;
								word-wrap: break-all;
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-line-clamp: 2;
								line-clamp: 2;
								-webkit-box-orient: vertical;
								text-shadow: 0 0 0.1px currentcolor;
							}
						}
						
					}
					.goods-sum {
						width: 100rpx;
						min-width: 100rpx;
					}
				}
				
				//	时间
				.goods-state {
					box-sizing: border-box;
					margin: 40rpx 0;
					padding: 32rpx 0 36rpx;
					background-color: rgba(255, 242, 242, 1);
					border-radius: 20rpx;
					border: 2rpx solid rgba(255, 222, 222, 1);
					.gs-item {
						display: flex;
						align-items: center;
						font-size: 14px;
						.gsi-label {
							display: flex;
							align-items: center;
							margin-right: 64rpx;
							color: rgba(0, 0, 0, 0.85);
							// text-shadow: 0 0 0.1px currentcolor;
							.gsil-tag {
								width: 10rpx;
								height: 10rpx;
								background-color: rgba(207, 26, 27, 1);
								border-radius: 50%;
								margin: 0 12rpx 0 32rpx;
							}
						}
					}
				}

				.order-item-b {
					display: flex;
					justify-content: flex-end;
					height: auto;
					overflow: hidden;
					
					button {
						max-height: 32px;
						margin: 0 0 0 24rpx;
						border-color: rgba(207, 26, 27, 1);
						color: #ffffff;
					}
				}
			}
		}
		
		// 卡友评论
		.tc-c-list {
			background-color: #ffffff;
			border-radius: 12rpx;
			padding: 20rpx 28rpx 28rpx;
			margin-top: 20rpx;
			&:nth-child(1){
				margin-top: 0;
			}
			// 头部基本信息
			.tc-cl-header {
				display: flex;
				justify-content: space-between;
				font-size: 12px;
				.tc-clh-left {
					display: flex;
					.tc-clhl-img {
						margin-right: 14rpx;
						image {
							width: 40px;
							height: 40px;
							border-radius: 50%;
						}
					}
					.tc-clhl-baseInfo {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						.tc-clhlb-number {
							display: flex;
							align-items: center;
							color: rgba(0, 0, 0, 1);
							.tc-clhlbn-car {
								font-size: 10px;
								color: rgba(114, 69, 0, 1);
								margin-left: 6rpx;
								padding: 0 2rpx;
								background: linear-gradient(180deg, #FFE9BE 0%, #FFD88B 100%);
								border-radius: 4rpx;
							}
						}
						.tc-clhlb-score {
							display: flex;
							align-items: center;
							text {
								margin-left: 6rpx;
							}
						}
					}
				}
				
				.tc-clh-right {
					color: rgba(0, 0, 0, 0.65);
				}
		
			}
			// 评价内容
			.tc-cl-main {
				.tc-clm-content {
					margin-top: 14rpx;
					font-size: 13px;
					color: rgba(0,0,0,0.85);
				}
				
				.tc-clm-store {
					margin: 20rpx 0;
					padding: 24rpx 36rpx 24rpx 18rpx;
					box-sizing: border-box;
					border: 2rpx solid rgba(0,0,0,0.06);
					display: flex;
					align-items: center;
					justify-content: space-between;
					.tc-clms-left {
						display: flex;
						align-items: center;
						image {
							width: 120rpx;
							height: 96rpx;
							border-radius: 6rpx;
						}
						.tc-clmsl-name {
							font-size: 15px;
							color: rgba(0, 0, 0, 0.85);
							margin-left: 28rpx;
							text-shadow: 0 0 0.1px currentColor;
						}
					}
				}
			}
			// 回复
			.tc-cl-reply {
				display: flex;
				.tc-clr-icon {
					image {
						width: 16px;
						height: 16px;
						margin-top: 4px;
					}
				}
				.tc-clr-des {
					font-size: 12px;
					.tc-clrd-label {
						color: rgba(255, 154, 56, 1);
						margin: 0 6rpx;
					}
				}
			}
		}
	
		// 评论内容超过两行省略
		.ellipsis-2 {
			line-height: 23px;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp:2;
		}
	}
</style>

